package com.liliudong.keelflower.common.gen;

import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(DataSourceProperties.class)
public class AutoGeneratorConfig {

    private final static String PARENT_PACKAGE_NAME = "com.liliudong.keelflower";
    private final static String ENTITY_NAME = "com.liliudong.keelflower.upms.biz";
    private final static String SERVICE_NAME = "com.liliudong.keelflower.upms.biz.modules";
    private final static String SERVICE_IMPL_NAME = "keel-flower-upms-biz";
    private final static String MAPPER_NAME = "keel-flower-upms-biz";
    private final static String XML_NAME = "keel-flower-upms-biz";
    private final static String CONTROLLER_NAME = "keel-flower-upms-biz";

    @Bean
    public DataSourceConfig dataSourceConfig(DataSourceProperties dataSourceProperties) {
        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setUrl(dataSourceProperties.getUrl());
        dataSourceConfig.setDriverName(dataSourceProperties.getDriverClassName());
        dataSourceConfig.setUsername(dataSourceProperties.getUsername());
        dataSourceConfig.setPassword(dataSourceProperties.getPassword());
        return dataSourceConfig;
    }

    @Bean
    public CodeGenerator codeGenerator(DataSourceConfig dataSourceConfig) {
        return new CodeGenerator(dataSourceConfig);
    }
}
